<?php
// +----------------------------------------------------------------------
// | snake
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 http://baiyf.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: NickBai <1902822973@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\NodeModel;
use app\admin\model\UserModel;
session_start();
class Index extends Base
{
   public function getIndex()
    {
         
       //  $Category=new NodeModel();
       //  $data=$Category->tree();
       //  print_r($data); die;

       // $this->assign('menu',$data);
       //  return $this->fetch('/index');
    }


    public function index()
    {
        // 获取权限菜单
        $node = new NodeModel();

        $this->assign([

            'menu' => $node->getMenu(session('rule')),
        ]);
         

          $array  = $node->getMenu(session('rule'));

        // var_dump($array);die();
        return $this->fetch('/index');
    }

    /**
     * 后台默认首页
     * @return mixed
     */
    public function indexPage()
    {   //fopen("http://www.wymlw.cn/getip.php","r");
        $data['order']=$data['fast']=$data['user']=0;
        $user = new UserModel();
        $token = $user->getToken();
        $data['visit_pv']="0";
        $time = date("Ymd",strtotime("-1 day"));//昨天，最晚时间不能超昨天
        $arrayName = array('begin_date' => $time,  'end_date' => $time);
        $url ="https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=$token";
        $result = $user->curl_post($url,$arrayName);
        $num=json_decode($result,true);//var_dump( $num);
        /*ref_date  时间： 如： "20170313"
          session_cnt 打开次数
          visit_pv  访问次数
          visit_uv  访问人数
          visit_uv_new  新用户数
          stay_time_uv  人均停留时长 (浮点型，单位：秒)
          stay_time_session 次均停留时长 (浮点型，单位：秒)
          visit_depth 平均访问深度 (浮点型)*/


        if ($_SESSION["think"]['id']==1) {
          $data['order'] = db('order')->where('state',0)->count();//订单总数
          $data['fast'] = db('rapidorder')->where('state',0)->count();//快速测试总数
          $data['user'] = db('user')->count();//用户总数
          if (@$num['list']==null) @$num['list'][0]['visit_pv']=0;
         
          $data['visit_pv'] = @$num['list'][0]['visit_pv'];
          
        }
        $sql = 'select VERSION()';
        $arr = db('rapidorder') ->query($sql);
        $parameter['versions'] =PHP_VERSION;//版本；
        $parameter['php_os'] =PHP_OS;;//服务器操作系统
        $parameter['SERVER_SOFTWARE'] =$_SERVER ['SERVER_SOFTWARE'];//服务器端信息
        $parameter['VERSION'] =$arr[0]['VERSION()'];//mysql版本
        date_default_timezone_set ('PRC');
        // $parameter['time'] =date("Y-m-d G:i:s");//后台当前时间$ip = $_SERVER["REMOTE_ADDR"];
        $parameter['ip'] ='http://'.$_SERVER['HTTP_HOST'].'/'.$_SERVER["REMOTE_ADDR"];//域名和ip 
        $parameter['get_cfg_var'] = get_cfg_var("max_execution_time")."秒 ";
        $this->assign('data',$data);
         $this->assign([

            'parameter' => $parameter,
        ]);
        return $this->fetch('index');
    }
    public function checkOrderNum()
    {

        if(request()->isAjax()){
          $counts = db('order')->where('state',0)->count();//订单总数
          //var_dump($_SESSION['ordernum']);
          if( @$_SESSION['ordernum'] == null|| @$_SESSION['ordernum'] == $counts){
              $_SESSION['ordernum'] = $counts;
              return 2 ;
            }elseif (@$_SESSION['ordernum'] < $counts) {
              $_SESSION['ordernum'] = $counts;
              return 1 ;
            }
          
        }
        // var_dump($array);die();
        //return $this->fetch('/index');
    }
}
